OPC Studio User's Guide and Reference
Examples - OPC UA File Transfer - Get file properties
View with Navigation Tools

The example below shows how to get OPC UA file properties (such as its size or writable status), using the file transfer client.

.NET

// Shows how to get OPC UA file properties (such as its size or writable status), using the file transfer client.
// Note: Consider using a higher-level abstraction, OPC UA file provider, instead.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.

using System;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.FileTransfer;
using OpcLabs.EasyOpc.UA.OperationModel;

namespace UADocExamples.FileTransfer._EasyUAFileTransferClient
{
    class GetFileProperties
    {
        public static void Main1()
        {
            // Unified Automation .NET based demo server (UaNETServer/UaServerNET.exe)
            UAEndpointDescriptor endpointDescriptor = "opc.tcp://localhost:48030";

            // A node that represents an instance of OPC UA FileType object.
            UANodeDescriptor fileNodeDescriptor = "nsu=http://www.unifiedautomation.com/DemoServer/ ;s=Demo.Files.TextFile";
            
            // Instantiate the file transfer client object
            var fileTransferClient = new EasyUAFileTransferClient();

            // Get properties of a specified file.
            UAFileProperties fileProperties;
            Console.WriteLine("Getting file properties...");
            try
            {
                fileProperties = fileTransferClient.GetFileProperties(endpointDescriptor, fileNodeDescriptor);
            }
            catch (UAException uaException)
            {
                Console.WriteLine("*** Failure: {0}", uaException.GetBaseException().Message);
                return;
            }

            // Display result
            Console.WriteLine();
            Console.WriteLine($"MimeType: {fileProperties.MimeType}");
            Console.WriteLine($"OpenCount: {fileProperties.OpenCount}");
            Console.WriteLine($"Size: {fileProperties.Size}");
            Console.WriteLine($"UserWritable: {fileProperties.UserWritable}");
            Console.WriteLine($"Writable: {fileProperties.Writable}");
            Console.WriteLine($"Timestamp: {fileProperties.Timestamp}");

            Console.WriteLine();
            Console.WriteLine("Finished...");
        }
    }
}

Python

# Shows how to get OPC UA file properties (such as its size or writable status), using the file transfer client.
# Note: Consider using a higher-level abstraction, OPC UA file provider, instead.
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
# OPC client and subscriber examples in Python on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-Python .
# Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
# a commercial license in order to use Online Forums, and we reply to every post.
# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc

# Import .NET namespaces.
from OpcLabs.EasyOpc.UA import *
from OpcLabs.EasyOpc.UA.FileTransfer import *
from OpcLabs.EasyOpc.UA.OperationModel import *


# Unified Automation .NET based demo server (UaNETServer/UaServerNET.exe).
endpointDescriptor = UAEndpointDescriptor('opc.tcp://localhost:48030')

# A node that represents an instance of OPC UA FileType object.
fileNodeDescriptor = UANodeDescriptor('nsu=http://www.unifiedautomation.com/DemoServer/ ;s=Demo.Files.TextFile')

# Instantiate the file transfer client object.
fileTransferClient = EasyUAFileTransferClient()

# Get properties of a specified file.
try:
    print('Getting file properties...')
    fileProperties = IEasyUAFileTransferExtension.GetFileProperties(fileTransferClient,
                                                                    endpointDescriptor, fileNodeDescriptor)
except UAException as uaException:
    print('*** Failure: ' + uaException.GetBaseException().Message)
    exit()

# Display result.
print()
print('MimeType: ', fileProperties.MimeType, sep='')
print('OpenCount: ', fileProperties.OpenCount, sep='')
print('Size: ', fileProperties.Size, sep='')
print('UserWritable: ', fileProperties.UserWritable, sep='')
print('Writable: ', fileProperties.Writable, sep='')
print('Timestamp: ', fileProperties.Timestamp, sep='')

print()
print('Finished.')

 

See Also

Examples - Client OPC UA File Providers

Concepts